package com.yowasa.xiuxian.engine.item.danyao;

import com.yowasa.xiuxian.annoations.Item;
import com.yowasa.xiuxian.engine.HoneEngine;
import com.yowasa.xiuxian.engine.hone.MentalInterface;
import com.yowasa.xiuxian.engine.item.ItemInterface;
import com.yowasa.xiuxian.entity.bo.user.UserBO;
import com.yowasa.xiuxian.entity.bo.user.UserBattle;
import com.yowasa.xiuxian.entity.enums.ItemTypeEnum;
import com.yowasa.xiuxian.service.helper.UserHelper;
import com.yowasa.xiuxian.util.DateXUtil;
import com.yowasa.xiuxian.util.RandomUtil;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

@Item(name = "脱胎换骨丹", type = ItemTypeEnum.DAN_YAO, price = 5)
public class TuoTaiHuanGuDan implements ItemInterface {
    @Autowired
    private UserHelper userHelper;


    @Override
    public String desc() {
        return "保留境界，从零开始重新突破至当前阶段，重新获取战斗属性\n暂无获取途径，游商极低概率刷新";
    }

    @Override
    public String effect(UserBO userBO) {

        UserBO bo = new UserBO();
        bo.setName(userBO.getName());
        bo.setUserId(userBO.getUserId());
        bo.setStage(1);
        bo.setLevel(0);
        bo.setUserAttr(userBO.getUserAttr());
        UserBattle userBattle = UserBattle.genBattleAttr(userBO.getUserAttr());
        bo.setUserBattle(userBattle);
        bo.setUserOriginBattle(userBattle);
        bo.setElement(userBO.getElement());
        bo.setUserConfig(userBO.getUserConfig());
        bo.setStartAt(new Date());
        bo.setAge(DateXUtil.START_AGE);
        bo.buildBaseInfo();
        bo.setAge(RandomUtil.randomInt(30, 400));

        MentalInterface mental = HoneEngine.mentalMap.get(bo.getUserConfig().getMental());
        for (int i = 1; i < userBO.getStage(); i++) {
            bo.setLevel(100);
            mental.breakUp(bo);
            userHelper.rebuildBattleInfo(bo);
            bo.buildBaseInfo();
        }

        userBO.setUserBattle(bo.getUserBattle());
        userBO.setUserOriginBattle(bo.getUserOriginBattle());
        return "你已重制战斗属性，请使用 /个人信息 查看";
    }


}
